Skip to content

added Endianness access from IFD to python #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

feefladder
Copy link
Contributor

@feefladder feefladder commented Jun 14, 2025

closes #91 No unit tests yet. There were none before me in the Python part. Would be happy to add some with some pointers.

I chose to duplicate the enum in Python, so users can access it as Endianness.LittleEndian in Python as well, using pyo3 macro derivation.

I added the repr(u16) and custom discriminant on PyEndianness for matching tiff structure. I could reflect that in src/reader.rs::Endianness or drop completely.

It seems that FromPyObject trait impl is needed if we want to pass it into a rust function from the python side. Since we don't currently do that, I didn't implement it. Could be nicely done to accept all of Endianness, u16 or String I think?

I'm a bit unsure of the location of PyEndianness Since its an enum I put it in python/src/enums.rs, even though all enums there are tags. On the rust side Endianness is in reader.rs, which makes sense implementation-wise I think? Should it actually be in python/src/reader.rs? Or should we wait for repo layout (#69).

@kylebarron
Copy link
Member

You can see my preferred way of implementing pyo3 enums here:

@feefladder feefladder force-pushed the endianness-access branch 2 times, most recently from b4b8261 to 6a4faee Compare June 17, 2025 13:33
Comment on lines +18 to +21
#[getter]
pub fn endianness(&self) -> PyEndianness {
self.0.endianness().into()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add this to the pyi file with the ImageFileDirectory type hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean Endianness type hint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I mean you need to describe this here:

class ImageFileDirectory:

Copy link
Contributor Author

@feefladder feefladder Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that (lines 15-16, also comment). What I meant is a -> Endianness type hint on the declaration

Comment on lines 1 to 6
use async_tiff::{
reader::Endianness,
tiff::tags::{
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor,
ResolutionUnit, SampleFormat,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this as module imports instead of crate imports.

Comment on lines 10 to 12
return str(self.value)

class Endianness(StrEnum):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add Python formatting to CI; as this would fail black/ruff fmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you opened an issue for that. I could pull it into this PR though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't know how to do that...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +15 to +16
@property
def endianness(self) -> Endianness: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that

Comment on lines +9 to +25

@property
def x(self) -> int:
"""The column index this tile represents."""

@property
def y(self) -> int:
"""The row index this tile represents."""

@property
def compressed_bytes(self) -> Buffer:
"""The compressed bytes underlying this tile."""

@property
def compression_method(self) -> CompressionMethod | int:
"""The compression method used by this tile."""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black added these

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all intents and purposes black and ruff format are the same, but they have some slight differences. Black is the older tool and ruff format is the preferred newer tool. Sorry for the confusion but we want to be using ruff format

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, I'd prefer for ruff format to be added as a separate PR with CI validation first, just like the cargo import ordering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add endianness property to the TIFF class
2 participants